import base64

Standard_Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
My_Alphabet = "J6BUi3aEzDMs4tPVRNb5qmA9pWdG2nSr7CLQZycvYHXgklwTuoeI1x0j8FKfhO+/="


def to_str(data):
    if isinstance(data, str):
        return data
    elif isinstance(data, bytes):
        return str(data, encoding='utf-8')
    elif isinstance(data, int):
        return str(data)


def to_bytes(data):
    if isinstance(data, bytes):
        return data
    if isinstance(data, int):
        data = str(data)

    return bytes(data, encoding='utf-8')


def decode(_str):
    return base64.b64decode(to_bytes(_str))


def encode(_str):
    return base64.b64encode(to_bytes(_str))


def decodeWithTrans(_str):
    res = []
    global My_Alphabet, Standard_Alphabet
    for _s in to_str(_str):
        res.append(Standard_Alphabet[My_Alphabet.index(_s)])

    return decode(''.join(res))


def encodeWithTrans(_str):
    enstr = to_str(encode(_str))
    res = []
    global My_Alphabet, Standard_Alphabet
    for _s in enstr:
        res.append(My_Alphabet[Standard_Alphabet.index(_s)])
    return to_bytes(''.join(res))


if __name__ == '__main__':
    a = encode(123)
    b = encodeWithTrans(123)

    print(a)
    print(b)

    c = decode(a)
    print(c)
    d = decode('MTIz')
    print(d)

    c = decodeWithTrans(b)
    print(c)
    d = decodeWithTrans(b'45zI')
    print(d)

    f = decodeWithTrans('45zI')
    print(f)
